// 配置路由的地方
import Vue from 'vue'
import VueRouter from "vue-router"

// 使用插件
Vue.use(VueRouter);

// 引入路由
import Home from '@/views/Home'
import Login from '@/views/Login'
import Register from '@/views/Register'
import Search from '@/views/Search'

let originPush = VueRouter.prototype.push
let originReplace = VueRouter.prototype.replace

// 重写push方法解决多次点击问题（promise）
VueRouter.prototype.push = function (location,resolve,reject){
    if(resolve && reject){
        originPush.call(this,location,resolve,reject)
    }else{
        originPush.call(this,location,() => {},() => {})
    }
}

VueRouter.prototype.replace = function (location,resolve,reject){
    if(resolve && reject){
        originReplace.call(this,location,resolve,reject)
    }else{
        originReplace.call(this,location,() => {},() => {})
    }
}
// 进行向外暴露
export default new VueRouter({
    routes:[
        {
            path:'/home',
            component:Home
        },
        {
            path:'/login',
            component:Login
        },
        {
            path:'/register',
            component:Register
        },
        {
            path:'/search/:keyword?',
            component:Search,
            name:'search'
        },
        // 重定向
        {
            path:'*',
            redirect:'/home'
        }

    
    ]

})